/**
 * 递归算法
 *
 * 反转字符串 —— 解决方案
 */
public class CharDigui {


    /**
     * 字符串翻转
     *
     * @return
     */
    public static String strRevers(String str) {
        if (str == null || str.length() == 0) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        for (int i = str.length() - 1; i >= 0; i--) {
            sb.append(str.charAt(i));
        }

        return sb.toString();

    }

    public static char[] charRevers1(char[] flag) {
        if (flag == null || flag.length == 0) {
            return flag;
        }

        char[] result = flag.clone();

        int length = result.length;
        char start;
        char end;

        for (int i = 0; i < length / 2; i++) {
            start = result[i];
            end = result[length - 1 - i];

            result[i] = end;

            result[length - i - 1] = start;
        }
        return result;
    }

    /**
     * 字符数组翻转  递归算法
     * @param flag
     * @return 返回串
     */
    public static char[] charRevers2(char[] flag) {
        if (flag == null || flag.length == 0) {
            return flag;
        }


        revers(flag, 0, flag.length - 1);
        return flag;
    }

    /**
     * 字符数组翻转  递归算法
     * @param orig
     * @param start
     * @param end
     */
    private static void revers(char[] orig, int start, int end) {
        if (start > orig.length / 2) {
            return;
        } else {
            char star = orig[start];
            orig[start] = orig[end];
            orig[end] = star;

            start += 1;
            end -= 1;

            revers(orig, start, end);

        }
    }







}
